#encoding=utf-8
import socket
import time
 
host = "192.168.137.84"      #服务器ip
port = 6666               #服务器端口号
 
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    # 选择IPv4地址以及TCP协议
print ("通信服务开启")
mySocket.bind((host, port))   # 绑定端口
mySocket.listen(5)       # 监听这个端口，可连接最多5个设备
 
if __name__ == '__main__':
    while True:  
        client, address = mySocket.accept()           # 接受客户端的连接请求

        try:  
            client.settimeout(120)                 # 设置2min时限
            while True:
                msg = client.recv(1024)       # 接收消息
                if not msg:
                    break
                else:
                    print(msg)
                    call(b'msg')
                mssg = raw_input()
                client.send(mssg)     # 发送消息  
 
        except socket.timeout:                # 超时
            print ('time out')
        
    mySocket.close()          # 关机
